package MyArray;

/**
 * 643. 子数组最大平均数 I
 * <p>
 * 给定 n 个整数，找出平均数最大且长度为 k 的连续子数组，并输出该最大平均数。
 */

public class findMaxAverage_643 {
    public static double findMaxAverage(int[] nums, int k) {
        Double maxx = - (double)Integer.MAX_VALUE;
        int total = 0;
        for (int i = 0; i < k; i++) {
            total += nums[i];
        }
        maxx = Math.max(maxx, (double)total / k);

        for(int j=k; j<nums.length; j++){
            total += nums[j];
            total -= nums[j-k];
            if((double)total / k > maxx){
                maxx = (double)total / k;
            }
        }
        System.out.println(maxx);
        return maxx;
    }

    public static void main(String[] args) {
        int[] array1 = new int[]{1,12,-5,-6,50,3};
        int[] array2 = new int[]{3, 6, 3, 3};
        System.out.println("5" + 2);
//        System.out.println(findSwapValues(array1, array2));
//        findMaxAverage(array1, 4);
    }
}
